<?php


namespace app\api\controller\v14;


use app\api\controller\v2\Auth;
use app\common\cachemodel\Fortune;
use app\common\cachemodel\Goods;
use app\common\cachemodel\live\LiveGiftSendRecord;
use app\common\cachemodel\NatalReport;
use app\common\cachemodel\Orders as OrdersCacheModel;
use app\common\cachemodel\OrdersGoods;
use app\common\cachemodel\OrdersLib;
use app\common\cachemodel\Recode;
use app\common\cachemodel\UserCoupon;
use app\common\cachemodel\ZhunleUserAccountRecord;
use app\common\cachemodel\ZlActivePrizeNumIncRecord;
use app\common\cachemodel\zlcr2\Zlcr2UserQuestion;
use app\common\cachemodel\ZlcrAstr;
use app\common\cachemodel\ZlcrCustomReportQuestion;
use app\common\cachemodel\ZlSynastryReport;
use app\common\cachemodel\ZlTarotRecords;
use app\common\lib\exception\ApiException;
use app\common\lib\PushQueue;
use app\zyhsapi\model\ZyhsConsultChatRtcRecord;
use Exception;
use think\Db;
use think\Log;
use think\response\Json;
use app\common\lib\Util;

/**
 * 1.9.8准币控制器
 * Class Coin
 * @package app\api\controller\v14
 */
class Coin extends Auth
{
    protected $msg;

    /**
     * 准币余额
     * @return Json
     * @throws Exception
     */
    public function coinNum()
    {
        $user_coin['coin_num'] = OrdersLib::getCoinNum($this->user['id']);
        return show(config('code.success'), '获取成功', $user_coin);
    }

    /**
     * 准币明细
     * @return Json
     * @throws Exception
     */
    public function coinDetail()
    {
        $user_coin_detail = (new ZhunleUserAccountRecord())->getUserCoinDetailListFromCache($this->user['id']);

        //获取直播礼物赠送及主播信息
        $giftIds = (new LiveGiftSendRecord())->giftSendRecord($this->user['id'], 1);
        $giftSendRecord = (new LiveGiftSendRecord())->batchGetInfoByIds($giftIds);
        $giftSendRecord = array_column($giftSendRecord, null, 'oid');
        $zlcrAstrModel = new ZlcrAstr();
        $zlcr3ConsultChatRtcRecordModel = new ZyhsConsultChatRtcRecord();
        // 流水类型1=>校准生辰 2=>日运 3=>月运 4=>年运 5=>幸运之城 6=>教学视频 7=>本命预测 8会员购买 9准币充值 10许愿充值
        $data = [];
        $isLiveGiftSend = false;
        foreach ($user_coin_detail['data'] as $datum)
        {
            $extend = json_decode($datum['extend'], true);
            $liveName = $extend['live_info']['name'] ?? '';
            $target = '';
            $link = '';
            $type = 0;
            if (isset($giftSendRecord[$datum['id']]))
            {
                $title = "{$giftSendRecord[$datum['id']]['gname']} ({$giftSendRecord[$datum['id']]['name']})";
                $isLiveGiftSend = true;
                $type_des = '已支付';
            } else
            {
                $type_des = '已支付';
                switch ($datum['order_type'])
                {
                    case 1:
                        $title = '校准生辰';
                        break;
                    case 2:
                        $title = '日运';
                        break;
                    case 3:
                        $title = '月运';
                        break;
                    case 4:
                        $title = '年运';
                        break;
                    case 5:
                        $title = '幸运之城';
                        break;
                    case 6:
                        $title = '教学视频';
                        break;
                    case 7:
                        $title = '一生报告';
                        break;
                    case 8:
                        $title = '会员';
                        break;
                    case 9:
                        if (Util::IsIos() && Util::CheckAppVersion('11.0.0') !== '小')
                        {
                            $title = 'Z币';
                        } else
                        {
                            $title = '准币';
                        }
                        $type_des = '已到账';
                        break;
                    case 10:
                        $title = '许愿充值';
                        $type_des = '已到账';
                        break;
                    case 11:
                        $title = '平台';
                        $type_des = '已到账';
                        break;
                    case 12:
                        $title = '精简月运';
                        break;
                    case 13:
                        $title = '精简本命报告';
                        break;
                    case 14:
                        $title = '商城商品';
                        break;
                    case 15:
                        $title = '定制报告';
                        break;
                    case 16:
                        $title = '塔罗报告';
                        break;
                    case 17:
                        $title = '合盘报告';
                        break;
                    case 19:
                        $title = "看盘解答（{$liveName}）";
                        break;
                    case 20:
                        $title = "骰子解答（{$liveName}）";
                        break;
                    case 21:
                        $title = "塔罗解答（{$liveName}）";
                        break;
                    case 22:
                        $title = '问答';
                        $questionGoodsType = '';
                        if ($datum['gid'])
                        {
                            $res = (new Zlcr2UserQuestion())->getQuestionType((int)$datum['gid']);
                            if ($res['type'] === 1)
                            {
                                $title = '问答-蹭看';
                            } else
                            {
                                if ($res['type'] === 2)
                                {
                                    $questionGoodsType = '追问';
                                }
                                switch ($res['sec'])
                                {
                                    case 1:
                                        $title = '问答-星盘' . $questionGoodsType;
                                        break;
                                    case 2:
                                        $title = '问答-骰子' . $questionGoodsType;
                                        break;
                                    case 3:
                                        $title = '问答-塔罗' . $questionGoodsType;
                                        break;
                                }
                            }
                        }
                        break;
                    case 28:
                        switch ($datum['gid'])
                        {
                            case 106:
                                $title = '用神详解';
                                break;
                            case 107:
                                $title = '72格局判定';
                                break;
                            default:
                                $title = '吉日吉时';
                                break;
                        }
                        break;
                    case 30:
                        $title = 'AI解问题';
                        break;
                    case 34:
                        $title = 'AI疗愈';
                        break;
                    case 100:
                        $extend = json_decode($datum['extend'], true);
                        if (isset($extend['rtc_id']))
                        {
                            $rtcInfo = $zlcr3ConsultChatRtcRecordModel->getInfoById($extend['rtc_id']);
                            $astrInfo = $zlcrAstrModel->getInfoById($rtcInfo['astr_id']);
                            $nickname = $astrInfo['nickname'];
                            $target = 'local';
                            $link = "rtc_consult_detail?id={$rtcInfo['chat_detail_id']}&need_auth=2";
                            $type = 1;
                        } else
                        {
                            $nickname = '';
                        }
                        $title = "连线咨询（{$nickname}）";
                        break;
                    case 120:
                        $extend = json_decode($datum['extend'], true);
                        $title = "打赏{$extend['astr_name']}-{$extend['gift_name']}x{$extend['num']}";
                        break;
                    default :
                        $title = '商品';
                        break;
                }

            }
            if ((int)$datum['consumer_type'] === 1)
            {
                $title = $title ? $title . '充值' : '';
                $price = $datum['coin_num'] ? '+' . $datum['coin_num'] : 0;
            } elseif ((int)$datum['consumer_type'] === 2)
            {
                if ($datum['order_type'] != 100)
                {
                    $title = $title ? '购买' . $title : '';
                }
                $price = $datum['coin_num'] ? '-' . $datum['coin_num'] : 0;
            } elseif ((int)$datum['consumer_type'] === 3)
            {
                $title = $title ? '赠送' . $title : '';
                if ($isLiveGiftSend)
                {
                    $price = $datum['coin_num'] ? '-' . $datum['coin_num'] : 0;
                } else
                {
                    $price = $datum['coin_num'] ? '+' . $datum['coin_num'] : 0;
                }
            } elseif ((int)$datum['consumer_type'] === 4)
            {
                $title = $title ? $title . '退款' : '';
                $price = $datum['coin_num'] ? '+' . $datum['coin_num'] : 0;
            } elseif ((int)$datum['consumer_type'] === 5)
            {
                $title = "打赏（{$liveName}）";
                $price = $datum['coin_num'] ? '-' . $datum['coin_num'] : 0;
            } elseif ((int)$datum['consumer_type'] === 6)
            {
                $title = "充值退款";
                $price = $datum['coin_num'] ? '-' . $datum['coin_num'] : 0;
                $type_des = '';
            } else
            {
                $price = $datum['coin_num'];
            }

            $data[] = [
                'title' => $title,
                'create_time' => date('Y-m-d H:i:s', $datum['create_time']),
                'price' => $price,
                'type_des' => $type_des,
                'target' => $target,
                'link' => $link,
                'type' => $type,
            ];
        }
        $user_coin_detail['data'] = $data;
        return show(config('code.success'), '获取成功', $user_coin_detail);
    }

    /**
     * 准币商品
     * @return Json
     * @throws Exception
     */
    public function coinGoods()
    {
        $arr = [
            'goods_data' => [],
            'coin_num' => OrdersLib::getCoinNum($this->user['id'])
        ];
        //获取准币商品信息
        if (Util::IsIos() && Util::CheckAppVersion('2.9.7') === '大')
        {
            $goods = array_values(config('zhunleorder.ios_coin_goods'));
            foreach ($goods as $good)
            {
                $arr['goods_data'][] = [
                    'num' => $good['coin_num'],
                    'price' => (string)$good['now_prize'],
                    'gid' => (int)$good['id']
                ];
            }
        } else
        {
            //获取商品信息
            $goods = (new Goods())->GoodsTypeInfo(9);
            foreach ($goods as $good)
            {
                $extend = $good['extend'] ? json_decode($good['extend'], true) : [];
                $coin_num = $extend['coin_num'] ?? 0;
                $arr['goods_data'][] = [
                    'num' => (int)$coin_num,
                    'price' => (string)(int)$good['now_prize'],
                    'gid' => (int)$good['id']
                ];
            }
        }

        return show(config('code.success'), '获取成功', $arr);
    }

    /**
     * 充值准币
     * @throws Exception
     */
    public function coinRecharge()
    {
        $type = input('param.type/d', 0);
        $gid = input('param.gid/d', 0);
        $trade_type = input('param.trade_type/d', 0);
        //检测参数并获取商品信息
        $goods = $this->CheckRechargeParam($type, $gid, $trade_type);
        if ($this->msg)
        {
            Log::write('v14充值请求参数有误：' . $this->msg . '请求参数:' . json_encode(['type' => $type, 'gid' => $gid], JSON_UNESCAPED_UNICODE), 'notice', true);
            return show(config('code.error'), $this->msg);
        }
        //许愿充值，需有自己的档案
        if ($type === 2)
        {
            $pray_date = (int)date('Ymd');
            $recode = (new \app\common\model\Recode())->getSelfRecode(['uid' => $this->user['id']]);
            if (!$recode)
            {
                return show(406, '档案缺失请添加档案');
            }
            $rid = $recode['id'];
        } else
        {
            $pray_date = 0;
            $rid = 0;
        }
        //获取订单描述语和订单编号
        $order_type_des = OrdersLib::createOrderId($goods['order_type']);
        $account = OrdersLib::getOrderAccountType($order_type_des['order_id'], $trade_type);
        //获取用户余额信息
        $user_coin = OrdersLib::getCoinNum($this->user['id']);
        $insertData = [
            'status' => 0,
            'account' => $account['account'],
            'uid' => $this->user['id'],
            'consumer_type' => 1,
            'order_type' => $goods['order_type'],
            'gid' => $gid,
            'pray_date' => $pray_date,
            'rid' => $rid,
            'total_amount' => $goods['received_price'] ?? $goods['now_prize'],//实际收入
            'pay_price' => $goods['now_prize'],//用户支付
            'coin_num' => $goods['coin_num'],
            'balance' => $goods['coin_num'] + $user_coin,
            'order_id' => $order_type_des['order_id'],
            'trade_type' => $trade_type,
            'create_time' => time(),
            'transaction_id' => ''
        ];
        //增加准币明细记录
        $oid = (new ZhunleUserAccountRecord())->SaveData($this->user['id'], $insertData);
        if ($oid)
        {
            //支付订单
            $arr = OrdersLib::unifyPayOrder([
                'oid' => $oid,
                'trade_type' => $trade_type,
                'total_amount' => $goods['now_prize'],
                'pay_des' => $order_type_des['pay_des'],
                'order_id' => $order_type_des['order_id'],
                'openid' => '',
                'callback_url' => '',
                'order_type' => $goods['order_type']
            ], 1);

            if ($this->headers['app-type'] === 'ios')
            {
                $arr['data']['skuId'] = 'apple_pay_' . $gid;
            }
            //若是苹果审核时，许愿充值skuid默认为44
            if ($this->is_apple_check && $gid >= 10000 && $gid < 20000)
            {
                $arr['data']['skuId'] = 'apple_pay_44';
            }
            //todo 测试删除 准币余额修改，添加明细记录
//        OrdersLib::UpdateCoin($order_type_des['order_id'], $goods['order_type'], $goods['now_prize'], $this->user['id']);
            return show(config('code.success'), '充值下单成功', $arr['data']);
        }
        return show(config('code.error'), '充值下单失败');
    }

    /**
     * 检测充值参数,并获取商品信息
     * @param int $type
     * @param int $gid
     * @param int $trade_type
     * @return array|mixed|string
     * @throws Exception
     */
    private function CheckRechargeParam($type, $gid, $trade_type)
    {
        $this->msg = '';
        $goods = [];
        $goods_info = [];
        $order_type = 0;
        $goods_config = config('goods');
        if (!$type)
        {
            return $this->msg = '缺少信息';
        }
        //1=>支付宝 2=》微信 4=》准币 9=》苹果
        if (!in_array($trade_type, [1, 2, 4, 9], true))
        {
            return $this->msg = '未知的支付方式';
        }
        //检测准币商品
        if ($type === 1)
        {
            if (!in_array($gid, $goods_config['coin_id'], true))
            {
                return $this->msg = '商品不存在';
            }
            //获取准币商品信息
            if (Util::IsIos() && Util::CheckAppVersion('2.9.7') === '大')
            {
                $goods = array_values(config('zhunleorder.ios_coin_goods'));
            } else
            {
                $goods = (new Goods())->GoodsTypeInfo(9);
            }
            $order_type = 9;
        }
        //检测许愿商品
        if ($type === 2)
        {
            if (!in_array($gid, $goods_config['pray_coin_id'], true))
            {
                return $this->msg = '商品不存在';
            }
            //获取许愿商品信息
            $goods = config('zhunleorder.pray_goods');
            $order_type = 10;
        }
        foreach ($goods as $good)
        {
            if (isset($good['extend']) && $good['extend'])
            {
                $extend = $good['extend'] ? json_decode($good['extend'], true) : [];
                $good['coin_num'] = $extend['coin_num'] ?? 0;
            }
            if ((int)$good['id'] === $gid)
            {
                $goods_info = $good;
                $goods_info['order_type'] = $order_type;
                break;
            }
        }
        if ($goods_info)
        {
            return $goods_info;
        }
        return $this->msg = '服务异常，请稍后再试';
    }

    /**
     * 准币下单
     * @return Json
     * @throws ApiException
     */
    public function coinPay()
    {
        $this->msg = '';
        $param['gids'] = input('param.gids', '');
        $param['order_type'] = input('param.order_type/d', 0);
        $param['param'] = input('param.param', '');
        $param['openid'] = input('param.openid', '');
        $param['password'] = input('param.password/s', '');
        $param['trade_type'] = 4;//准币支付
        $param = OrdersLib::pay_order_param_format($this->user['id'], $param);
        if ($this->msg)
        {
            Log::write('v14准币支付请求参数有误：' . $this->msg, 'notice', true);
            return show(config('code.error'), $this->msg);
        }
        //使用免费券或支付金额小于0
        $data = $this->SaveFreeOrder($param);
        //如果是定制报告，那么发送钉钉通知
        if (15 === $param['order_type'])
        {
            Util::sendZlcrMsg(0, ['准币支付']);
        }
        return show(config('code.success'), '下单成功', ['order_id' => $data]);
    }

    /**
     * 运势下单
     * @param int $rid
     * @param int $start_time
     * @param int $order_type
     * @return bool|int|string
     */
    private function pay_fortune($rid, $start_time, $order_type)
    {
        $arr = [
            'type' => $order_type - 1,
            'rids' => $rid,
            'time' => $start_time,
            'create_time' => $this->request->time(),
        ];
        try
        {
            $fid = (new Fortune())->insertGetId($arr); //每日运势id
        }
        catch (Exception $e)
        {
            return false;
        }

        return $fid;
    }

    /**
     * 添加中间表数据
     * @param $rid
     * @param $gids
     * @param $oid
     * @return bool
     */
    private function insertMiddle($rid, $gids, $oid)
    {
        $array = [];
        foreach ($gids as $k => $v)
        {
            $array[] = [
                'gid' => $v,
                'oid' => $oid,
                'rid' => $rid
            ];
        }
        //中间表
        try
        {
            (new OrdersGoods())->insertAll($array);
        }
        catch (Exception $e)
        {
            return false;
        }

        return true;
    }

    /**
     * 生成订单数据并入队
     * @param $param [cid,rid,start_time,order_type,gids,out_trade_no,reid,extend,goods_info]
     * @return array
     * @throws ApiException
     * @throws Exception
     */
    private function SaveFreeOrder($param)
    {
        $order_type = (int)$param['order_type'];
        $middle_res = true;
        $CouponModel = new UserCoupon();
        $now_time = time();
        $gid = current($param['gids']);
        //订单状态
        $status = OrdersLib::getOrderStatus($param['gids'], (int)$order_type);
        Db::startTrans();
        try
        {
            (new Recode())->UpdateData($this->user['id'], $param['rid'], [], 1);//or_day生成
            //若是运势，则添加运势中间表数据
            if (in_array($order_type, [2, 3, 4], true))
            {
                $middle_res = $this->pay_fortune($param['rid'], $param['start_time'], $order_type);
            }
            if ($middle_res === false)
            {
                throw new ApiException('下单失败,请重新操作');
            }
            //生成订单数据
            $insert = [
                'order_type' => $order_type,
                'uid' => $this->user['id'],
                'gid' => $gid,
                'order_id' => $param['out_trade_no'],
                'reid' => $param['reid'],
                'fid' => $middle_res === true ? 0 : $middle_res,
                'trade_type' => $param['trade_type'],
                'total_amount' => $param['price'],
                'create_time' => $now_time,
                'update_time' => $now_time,
                'pay_time' => $now_time,
                'status' => $status,
                'account' => 0,
                'extend' => $param['extend']
            ];
            // 生成订单到数据库
            $OrdersCacheModel = new OrdersCacheModel();
            //生成订单数据
            $oid = $OrdersCacheModel->SaveData($insert);
            if ($oid === false)
            {
                throw new ApiException('下单失败,请重新操作');
            }
            //添加中间表数据
            if ($param['rid'])
            {
                $middle_res = $this->insertMiddle($param['rid'], $param['gids'], $oid);
                if ($middle_res === false)
                {
                    throw new ApiException('下单失败,请重新操作');
                }
            }
            //商品购买人数自增,教学视频和本命报告根据课程进行缓存数据
            if (in_array($order_type, [6, 7], true))
            {
                $OrdersCacheModel->SaveTotalPrepaidOrder($order_type, $gid);
            } elseif ($order_type === 17)
            {   // 合盘报告 根据gid自增 和gid与关系ID【relation_id】新增 维护两个缓存
                $extend = \GuzzleHttp\json_decode($param['extend'], true);
                $OrdersCacheModel->SaveTotalPrepaidOrder($order_type, $extend['synastry_report']['srid']); // 根据srid自增
                $OrdersCacheModel->SaveTotalPrepaidOrder($order_type, $extend['synastry_report']['srid'], $extend['synastry_report']['relation_id']); // 根据srid与关系ID【relation_id自增
            } else
            {
                $OrdersCacheModel->SaveTotalPrepaidOrder($order_type, 0);
            }

            //修改优惠券状态为已锁定
            if ($param['cid'])
            {
                $res = $CouponModel->use_return($this->user['id'], $param['cid'], ['status' => 1, 'oid' => $oid, 'update_time' => $this->request->time()]);
                if ($res === false)
                {
                    throw new ApiException($CouponModel->getError());
                }
            }

            //生成第三方数据和入队
            switch (true)
            {
                case $order_type === 1://校准生辰入队
                    $this->RecQueue($param['reid'], $oid, $param['out_trade_no']);
                    break;
                case in_array($order_type, [3, 4], true)://运势入队
                    $this->FortuneQueue($this->user['id'], $oid);
                    break;
                case $order_type === 5://地图入队
                    (new PushQueue())->Map($param['out_trade_no']);
                    break;
                case $order_type === 7://本命预测入队
                    $this->NatalQueue($param['rid'], $param['gids'], $param['out_trade_no']);
                    break;
                case $order_type === 8://若是vip，更新vip有效期和生效状态
                    $middle_res = $this->pay_vip($insert, $gid);
                    break;
                case $order_type === 15: //修改问题状态和问题支付时间并入队
                    $questionModel = new ZlcrCustomReportQuestion();
                    //问题入队
                    $questionModel->orderReportQueue($insert['order_id']);
                    break;
                case $order_type === 16 : //修改塔罗记录状态
                    $extend = json_decode($insert['extend'], true);
                    $taroId = $extend['history']['id'];
                    (new ZlTarotRecords())->updateData($taroId, ['status' => 1]);
                    break;
                case $order_type === 17:
                    $this->SynastryQueue($insert, (int)$gid, null);
                    break;

            }
            //更新星力值
            if ($order_type !== 8)
            {   // VIP订单除外 更新星力值，  VIP星力值已经更新过了，禁止重复更新
                OrdersLib::UpdateVipBoon($insert, $gid, true);
            }
            if ($middle_res === false)
            {
                throw new ApiException('下单失败,请重新操作');
            }
            //塔罗记录更新订单编号数据
            if ($order_type === 16)
            {
                (new ZlTarotRecords())->updateData($param['history_id'], ['order_num' => $param['out_trade_no']]);
            }
            //准币余额修改，添加明细记录
            OrdersLib::UpdateCoin($param['out_trade_no'], $param['order_type'], $param['price'], $this->user['id'], 2, $param['trade_type']);
            //更新订单详情缓存
            $OrdersCacheModel->UpdateCache($param['out_trade_no'], $status);
            Db::commit();
        }
        catch (Exception $e)
        {
            Db::rollback();
            Log::write('准币下单失败：' . $e->getMessage() . '【' . $e->getFile() . $e->getLine() . '】', 'error');
            throw new ApiException('下单失败,请重新操作');
        }

        // 开盲盒任务判断
        (new ZlActivePrizeNumIncRecord())->goodsTask($this->user['id'], $gid, $param['out_trade_no']);

        Util::logRealTimeAnalyzeWrite(4, [
            'coin_pay_uid' => $this->user['id'] ?? '',
            'coin_pay_order_id' => $param['out_trade_no'],
            'coin_pay_order_type' => $order_type,//1=>校准生辰 2=>日运 3=>月运 4=>年运 5=>幸运之城 6=>教学视频 7=>本命预测 8=>会员购买 9=>准币充值 10=>祈福充值 11=>赠送
            'coin_pay_total_amount' => $param['price'],
            'coin_pay_gid' => implode('-', $param['gids']),
            'coin_pay_consumer_type' => 2 // 1=>充值 2=>消费,3=>赠送,4=>退款
        ]);

        return $param['out_trade_no'];
    }

    /**
     * 校准生辰入队
     * @param $reid
     * @param
     * $oid
     * @param $out_trade_no
     * @throws Exception
     */
    private function RecQueue($reid, $oid, $out_trade_no)
    {
        (new PushQueue())->Rectification($this->user, $reid, $oid, $out_trade_no);
    }

    /**
     * 运势入队
     * @param $uid
     * @param $oid
     * @return bool|mixed
     * @throws Exception
     */
    private function FortuneQueue($uid, $oid)
    {
        return (new PushQueue)->Fortune(['uid' => $uid, 'oid' => $oid]);
    }

    /**
     * 本命预测入队加结果数据写入
     * @param int $rid
     * @param array $gids
     * @param string $order_id
     * @throws Exception
     */
    private function NatalQueue($rid, $gids, $order_id)
    {
        $NatalReportModel = new NatalReport();
        $NatalReportModel->SaveQueue($this->user['id'], $rid, $gids, $order_id);
    }

    /**
     * 本命预测入队加结果数据写入
     * @param array $orders
     * @param int $unlock_gid
     * @param null $queueDelay 队列延迟时间
     * @throws Exception
     */
    private function SynastryQueue(array $orders, int $unlock_gid, $queueDelay = null)
    {
        $extend = json_decode($orders['extend'], true);
        (new ZlSynastryReport())->SaveQueue($this->user['id'], $unlock_gid, $extend['synastry_report'], $orders['order_id'], $queueDelay);
    }

    /**
     * 会员下单
     * @param $orders
     * @param $gid
     * @return bool
     */
    private function pay_vip($orders, $gid)
    {
        return OrdersLib::UpdateVipStatus($orders, $gid);
    }
}
